var SysMenuPage = {
	add:function() {
		var newNode = menuTree.addNode(menuTree.getCurrentNode());
		if (newNode) {
			newNode.enabled = '1';
			newNode.weight = '1';
		}
		$("#menuDetailFrm").autofill(newNode);
	},
	del:function() {
		var currNode = menuTree.getCurrentNode();
		menuTree.removeNode(currNode);
		$("#menuDetailFrm")[0].reset();
	},
	refresh:function() {
		menuTree.refresh(true);
		$("#menuDetailFrm")[0].reset();
	},
	MENU_STRUCTURE:['resId','resName','resPid','resPath','weight','enabled','resExt1'],
	save:function() {
		var data = menuTree.getRecorder().pack(SysMenuPage.MENU_STRUCTURE);
		saveMenuAjax.setData($.toJSON(data));
		saveMenuAjax.send();
	},
	onSaveSucc:function(data,status,xhr) {
		SysMenuPage.refresh();
		MsgBox.info('保存成功！');
	},
	onValueChanged:function(ele) {
		var currNode = menuTree.getCurrentNode();
		if (!currNode) {
			return;
		}
		var obj = $("#menuDetailFrm").serializeObject();
		if (this.validate(obj)){
			$.extend(currNode, obj);
			menuTree.updateNode(currNode, true);
		}
	},
	// 验证节点
	validate:function(currNode) {
		if (StringUtil.isBlank(currNode.resName)) {
			$.messager.error('菜单名称不能为空！');
			return false;
		}
		if (StringUtil.lengthGreaterThan(currNode.resName, 32)) {
			$.messager.error('菜单名称过长，超出了32个字符');
			return false;
		}
		if (StringUtil.lengthGreaterThan(currNode.resPath, 100)) {
			$.messager.error('地址过长，超出了100个字符');
			return false;
		}
		if (StringUtil.lengthGreaterThan(currNode.resExt1, 64)) {
			$.messager.error('图标字符过长，超出了64个字符');
			return false;
		}
		return true;
	},
	onSelected:function() {
		var node = menuTree.getCurrentNode();
		$("#menuDetailFrm").autofill(node);
	}
};